package com.itheima.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Permission;
import com.itheima.health.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author liu
 * @version 1.0.0
 * @createTime 2020年10月09日
 * @Description 权限控制
 */
@RestController
@Slf4j
@RequestMapping("/permission")
public class PermissionController {
@Reference
private PermissionService permissionService;

    /**
     * 分页查询
     * @param queryPageBean 封装el需要的数据
     * @return
     */
    @RequestMapping("/findPage")
public Result findPage(QueryPageBean queryPageBean){
   log.info("[权限分页查询]data:{}",queryPageBean);
        PageResult pageResult=permissionService.pageQuery(queryPageBean);

    return new Result(true,"权限分页查询成功",pageResult);
}

    /**
     * 添加权限
     * @param permission
     * @return
     */
    @RequestMapping("add")
public Result add(@RequestBody Permission permission){
          log.info("[新增权限data:{}]",permission);
           permissionService.add(permission);

        return new Result(true, "新增权限成功");
}

    /**
     * 查找根据id
     * @param id
     * @return
     */
    @RequestMapping("findById")
public Result findById(Integer id){
        log.info("[权限根据id查询数据 ]id:{}",id);
       Permission permission =permissionService.findById(id);

return new Result(true,"权限编辑回显成功",permission);
}

@RequestMapping("edit")
public Result edit(@RequestBody Permission permission){
        log.info("[编辑页面]permission:{}",permission);
        permissionService.edit(permission);

        return  new Result(true,"编辑成功");
}

@RequestMapping("delete")
public Result delete(Integer id){
        permissionService.delete(id);
        return new Result(true,"删除权限成功");
}
@RequestMapping("findAll")
public  Result findAll(){
       List<Permission> list=permissionService.findAll();

        return  new Result(true,"查询所有成功",list);
}
}
